package fr.uhp.mpr.data;

public class Intervalle {

	protected double start;
	protected double end;
	protected boolean inStart;
	protected boolean inEnd;
	
	public Intervalle(double start, double end){
		this.start = start;
		this.end = end;
		this.inStart = true;
		this.inEnd = false;
	}

	public Intervalle(double start, double end, boolean inStart, boolean inEnd) {
		this.start = start;
		this.end = end;
		this.inStart = inStart;
		this.inEnd = inEnd;
	}

	public double getStart() {
		return start;
	}

	public void setStart(double start) {
		this.start = start;
	}

	public double getEnd() {
		return end;
	}

	public void setEnd(double end) {
		this.end = end;
	}

	public boolean isInStart() {
		return inStart;
	}

	public void setInStart(boolean inStart) {
		this.inStart = inStart;
	}

	public boolean isInEnd() {
		return inEnd;
	}

	public void setInEnd(boolean inEnd) {
		this.inEnd = inEnd;
	}

	public boolean contains(double n) {
		if(n>=this.start && n<this.end && this.inStart && !this.inEnd) return true;
		if(n>=this.start && n<=this.end && this.inStart && this.inEnd) return true;
		if(n>this.start && n<=this.end && !this.inStart && this.inEnd) return true;
		if(n>this.start && n<this.end && !this.inStart && !this.inEnd) return true;
		return false;
	}
	
	public boolean compare(Intervalle i){
		return ((i.end==end)&&(i.start==start));
	}
	
	public String display() {
		String res = "entre ";
		if (this.start == Double.NEGATIVE_INFINITY)
			res += "moins l'infini et ";
		else
			res += this.start + " et ";
		
		if (this.end == Double.POSITIVE_INFINITY)
			res += "l'infini";
		else
			res += this.end;
		return res;
	}
	
	@Override
	public String toString() {
		String res = new String();
		if(inStart)
			res += "[";
		else
			res += "]";
		if(start == Double.NEGATIVE_INFINITY)
			res += "inf";
		else
			res += start;
		res += ",";
		if(end == Double.NEGATIVE_INFINITY)
			res += "inf";
		else
			res += end;
		if(inEnd)
			res += "]";
		else
			res += "[";
		return res;
	}
}
